<template>
	<view>
		<view class="bigbox">
			<view class="box">
				<image src="../../static/mylogo.png" mode="aspectFit"></image>
				<text>研海</text>
			</view>
		</view>
		<view class="userMsgbox">
			<view class="usernamebox">
				<view class="usernametext">用户名:</view>
				<view class="username">
					<input type="text" v-model="name" class="name"></input>
				</view>
			</view>
			<view class="sexbox">
				<view class="sextext">性别:</view>
				<view class="sex">
					<view class="man" @click="chooseman">
						<image src="../../static/unman.png" v-if="sex != 1" mode="aspectFit"></image>
						<image src="../../static/man.png" v-if="sex == 1" mode="aspectFit"></image>
						<text v-if="sex == 1" style="color: #1296db; font-weight: bold;">男</text>
						<text v-if="sex != 1">男</text>
					</view>
					<view class="woman" @click="chosewoman">
						<image src="../../static/unwoman.png" v-if="sex != 2" mode="aspectFit"></image>
						<image src="../../static/woman.png" v-if="sex == 2" mode="aspectFit"></image>
						<text v-if="sex == 2" style="color: #d4327a; font-weight: bold;">女</text>
						<text v-if="sex != 2">女</text>
					</view>
				</view>
			</view>
			<view class="telnumber">
				<view class="teltext">电话号码：</view>
				<view class="tel">
					<input type="text" v-model="phonenumber" class="number"></input>
				</view>
			</view>
			<view class="telnumber">
				<view class="teltext">密码：</view>
				<view class="tel">
					<input type="password" v-model="password" class="number"></input>
				</view>
			</view>
			<view class="telnumber">
				<view class="teltext">确认密码：</view>
				<view class="tel">
					<input type="password" v-model="ensurePW" class="number"></input>
				</view>
			</view>
			<view class="subtitle" v-if="this.password != this.ensurePW && this.ensurePW.length > 0"
				style="color: #FF0000;">两次密码不一致</view>
			<view class="telnumber">
				<view class="teltext">目标院校：</view>
				<view class="tel">
					<picker @change="choseuniversity" :value="index" :range="universityarray">
						<view class="number" style="color: #333333;">{{universityarray[index]?universityarray[index]:"选择院校"}}</view>
					</picker>
				</view>
			</view>
			<view class="telnumber">
				<view class="teltext">目标专业：</view>
				<view class="tel">
					<picker @change="chosemajor" :value="number" :range="majorarray">
						<view class="number">{{majorarray[number]?majorarray[number]:"选择专业"}}</view>
					</picker>
				</view>
			</view>
			<button class="button" @click="register">注册</button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				sex: 0,
				name: "",
				password: "",
				ensurePW: "",
				phonenumber: "",
				university: "",
				major: "",
				universityarray: ['浙江工商大学', '清华大学', '北京大学', '厦门大学', '浙江大学', '宁波大学', '浙江工业大学'],
				index: null,
				number:null,
				majorarray: ['计算机科学与技术','软件工程','人工智能','金融']
			};
		},
		onLoad() {

		},
		methods: {
			register() {
				console.log(this.name, this.sex, this.phonenumber, this.password, this.ensurePW, this.university, this.major)
				uni.request({
				    url: this.baseurl + '/register',
					method: "POST",
					header: {
						'content-type': "application/json",
					},
					data: {
						userId: this.phonenumber,
						password: this.password,
						nickname: this.name,
						school: this.university,
						major: this.major
					},
				    success: (res) => {
						console.log("success");
						uni.showToast({
							title: "注册成功",
							icon: 'none',
							duration: 2000,
						});
						setTimeout(() => {
							uni.navigateBack({
							});
						}, 1000);
				    }
				});
			},
			chooseman() {
				this.sex = 1;
			},
			chosewoman() {
				this.sex = 2;
			},
			gotoFirstPage() {
				console.log("名字：" + this.name + "密码：" + this.password + "性别：" +
					this.sex + "目标院校：" + this.university + "目标专业：" + this.major)
				uni.switchTab({
					url: "../firstpage/FirstPage"
				})
			},
			choseuniversity: function(e) {
				//this.university = this.universityarray[e.target.value]
				this.index = e.target.value
				this.university = this.universityarray[e.target.value]
				console.log(this.university)
			},
			chosemajor: function(e) {
				//this.university = this.universityarray[e.target.value]
				this.number = e.target.value
				this.major = this.majorarray[e.target.value]
				console.log(this.major)
			},
		}

	}
</script>

<style lang="scss">
	.bigbox {
		display: flex;
		flex-direction: row;
		justify-content: center;

		.box {
			margin-top: 150rpx;
			//background-color: #333333;
			//height: 150rpx;
			//width: 200rpx;
			display: flex;
			flex-direction: row;

			image {
				//background-color: #4CD964;
				height: 200rpx;
				width: 200rpx;
			}

			text {
				display: flex;
				align-items: center;
				justify-content: center;
				//margin-top: 40rpx;
				font-size: 80rpx;
				font-weight: bold;
				//background-color: #F0AD4E;
			}
		}
	}

	.userMsgbox {
		display: flex;
		flex-direction: column;
		//width: 650rpx;
		//background-color: #007AFF;
		margin-top: 30rpx;
		//justify-content: flex-end;
		align-items: flex-end;

		.usernamebox {
			display: flex;
			flex-direction: row;
			align-items: center;
			height: 100rpx;
			//width: 600rpx;
			//background-color: #333333;
			justify-content: flex-end;
			margin-right: 30rpx;

			.usernametext {
				font-weight: bold;
				margin-right: 40rpx;
			}

			.username {
				display: flex;
				align-items: center;
				border-radius: 10rpx;
				height: 70rpx;
				width: 500rpx;
				background-color: #F2F2F2;

				.name {
					//background-color: #007AFF;
					padding-left: 10rpx;
					width: 500rpx;
				}
			}
		}

		.sexbox {
			display: flex;
			flex-direction: row;
			align-items: center;
			height: 100rpx;
			//width: 600rpx;
			//background-color: #333333;
			justify-content: flex-end;
			margin-top: 10rpx;
			margin-right: 30rpx;

			.sextext {
				font-weight: bold;
				margin-right: 40rpx;
			}

			.sex {
				border-radius: 10rpx;
				height: 70rpx;
				width: 500rpx;
				//background-color: #F2F2F2;
				display: flex;
				flex-direction: row;
				justify-content: space-around;

				.man {
					height: 70rpx;
					//background-color: #4CD964;
					display: flex;
					align-items: center;
					justify-content: center;

					image {
						height: 50rpx;
						width: 50rpx;
					}

					text {
						margin-left: 10rpx;
					}

				}

				.woman {
					height: 70rpx;
					display: flex;
					align-items: center;
					justify-content: center;

					image {
						height: 50rpx;
						width: 50rpx;
					}

					text {
						margin-left: 10rpx;
					}
				}
			}
		}

		.telnumber {
			display: flex;
			flex-direction: row;
			align-items: center;
			height: 100rpx;
			//width: 600rpx;
			//background-color: #333333;
			justify-content: flex-end;
			margin-right: 30rpx;

			.teltext {
				font-weight: bold;
				margin-right: 20rpx;
			}

			.tel {
				display: flex;
				align-items: center;
				border-radius: 10rpx;
				height: 70rpx;
				width: 500rpx;
				background-color: #F2F2F2;

				.number {
					//background-color: #007AFF;
					width: 500rpx;
					padding-left: 10rpx;
				}
			}
		}

		.subtitle {
			//background-color: #007AFF;
			margin-right: 40rpx;
		}
	}

	.button {
		margin-top: 300rpx;
		display: flex;
		justify-content: center;
		align-items: center;
		color: #FFFFFF;
		background-color: #007AFF;
		border-radius: 20rpx;
		height: 80rpx;
		width: 200rpx;
	}
</style>
